#include "QtUI/Impl/ProjectRelatedCommandEnabler.hpp"
#include "Ctrl/ControlCenter.hpp"
#include "Ctrl/ProjectController.hpp"
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
#include <QtGui/QAction>
#include <cassert>

namespace QtUI { namespace Impl
{

ProjectRelatedCommandEnabler::ProjectRelatedCommandEnabler( QAction* pBoundAction )
	: pActionToCtrl_( pBoundAction)
{
	using namespace boost::lambda;

	assert( NULL != pActionToCtrl_);
	pActionToCtrl_->setEnabled( false);
	Ctrl::ControlCenter::instance().prjController().subscribeToProjectChanged( 
		bind( &ProjectRelatedCommandEnabler::changeProject, this, _1));
}

// ---------------------------------------------------------------------------------------------------------------------

void ProjectRelatedCommandEnabler::changeProject( Model::Project* newCurPrj )
{
	pActionToCtrl_->setEnabled( NULL != newCurPrj);
}

}} // namespace QtUI // namespace Impl

